import * as actionTypes from './constants'
import {
  getArtistList,
  getArtistDetail,
  getArtistSongs,
  getArtistAlbums,
  getArtistMvs,
  getArtistIntro
} from '@/services/artist-api'
const changeArtistListAction = artistList => ({
  type: actionTypes.CHANGE_ARTIST_LIST_ACTION,
  artistList
})
export const getArtistListAction = (type, area,initial = -1) => {
  return async dispatch => {
    const res = await getArtistList(type, area,initial)
    dispatch(changeArtistListAction(res.artists))
  }
}
const changeCurrentTypeAction = currentType => ({
  type: actionTypes.CHANGE_CURRENT_TYPE_ACTION,
  currentType
})
export const getCurrentTypeAction = type => {
  return dispatch => {
    dispatch(changeCurrentTypeAction(type))
  }
}
const changeCurrentAreaAction = currentArea => ({
  type: actionTypes.CHANGE_CURRENT_AREA_ACTION,
  currentArea
})
export const getCurrentAreaAction = area => {
  return dispatch => {
    dispatch(changeCurrentAreaAction(area))
  }
}
const changeCurrentTitleAction = currentTitle => ({
  type: actionTypes.CHANGE_CURRENT_TITLE_ACTION,
  currentTitle
})
export const getCurrentTitleAction = title => {
  return dispatch => {
    dispatch(changeCurrentTitleAction(title))
  }
}
const changeCurrentInitailAction = currentInitial => ({
  type: actionTypes.CHANGE_CURRENT_INITIAL_ACITON,
  currentInitial
})
export const getCurrentInitialAction = initial => {
  return dispatch => {
    dispatch(changeCurrentInitailAction(initial))
  }
}
const changeArtistDetailAction = artistDetail => ({
  type: actionTypes.CHANGE_ARTIST_DETAIL_ACTION,
  artistDetail
})
const changeArtistIdAction = artistId => ({
  type: actionTypes.CHANGE_ARTIST_ID_ACTION,
  artistId
})
export const getArtistDetailAction = id => {
  return async dispatch => {
    const res = await getArtistDetail(id)
    dispatch(changeArtistDetailAction(res.data.artist))
    dispatch(changeArtistIdAction(id))
  }
}
const changeArtistSongsAction = artistSongs => ({
  type: actionTypes.CHANGE_ARTIST_SONGS_ACTION,
  artistSongs
})
export const getArtistSongsAction = id => {
  return async dispatch => {
    const res = await getArtistSongs(id)
    console.log(res, 'song'); 
    dispatch(changeArtistSongsAction(res.hotSongs))
  }
}
const changeArtistAlbumsAction = artistAlbums => ({
  type: actionTypes.CHANGE_ARTIST_ALBUMS_ACTION,
  artistAlbums
})
export const getArtistAlbumsAction = (id,offset) => {
  return async dispatch => {
    const res = await getArtistAlbums(id,offset)
    console.log(res, 'album');
    dispatch(changeArtistAlbumsAction(res.hotAlbums))

  }
}
const changeArtistMvsAction = artistMvs => ({
  type: actionTypes.CHANGE_ARTIST_MVS_ACTION,
  artistMvs
})
export const getArtistMvsAction = (id,offset) => {
  return async dispatch => {
    const res = await getArtistMvs(id,offset)
    console.log(res, 'mv');
    dispatch(changeArtistMvsAction(res.mvs))
  }
}
const changeArtistIntroAction = artistIntro => ({
  type: actionTypes.CHANGE_ARTIST_INTRO_ACTION,
  artistIntro
})
const changeArtistDescAction = artistDesc => ({
  type: actionTypes.CHANGE_ARTIST_DESC_ACTION,
  artistDesc
})
export const getArtistIntroAction = id => {
  return async dispatch => {
    const res = await getArtistIntro(id)
    console.log(res, 'intro');
    dispatch(changeArtistIntroAction(res.introduction))
    dispatch(changeArtistDescAction(res.briefDesc))
  }
}